package com.shujia.core

import org.apache.spark.{SparkConf, SparkContext}

import java.util.Random


object Code33PiCompute {
  def main(args: Array[String]): Unit = {
    val conf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("LogDataCompute")
    val sc = new SparkContext(conf)

    var pointNum = 10000 * 10000 * 100
//    var partition = 10
    val filterNum: Long = sc
      .range(0, pointNum, 1)
      .map(x => {
        getPoint()
      })
      .filter {
        case (x, y) => {
          x * x + y * y <= 1
        }
      }
      .count()

    println(s" Pi的值为：${4 * (filterNum / pointNum.toDouble)}")

  }

  def getPoint(): (Double, Double) = {
    (Math.random() * 2 - 1, Math.random() * 2 - 1)
  }
}
